home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / GL / demograph / slider.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  196 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include "stdio.h"
  18. #include "gl.h"
  19. #include "device.h"
  20. #include "demograph.h"
  21.  
  22. #define FMFONT 0
  23. #define DBUG FALSE
  24.  
  25. #define Line(x1,y1,x2,y2)  sboxfi((x1),(y1),(x2),(y2))
  26.  
  27. extern CATEGORY *curcategory;
  28. extern WINREC winrec;
  29. extern int updatetext;
  30. extern DATA *curdata;
  31.  
  32. /* only for eight bitplane kluge */
  33. extern MACHREC machrec;
  34.  
  35. extern void (*drawmap)(float *data);
  36.  
  37. v2ixy(x,y)
  38. long x,y;
  39. {
  40.     long vect[2];
  41.     vect[0] = x;
  42.     vect[1] = y;
  43.     v2i(vect);
  44. }
  45.  
  46.  
  47. updateslider()
  48. {
  49.     float range;
  50.     int x, oldx;
  51.     int sminx = winrec.sliderminx;
  52.     int smaxx = winrec.slidermaxx;
  53.     int sminy = winrec.sliderminy;
  54.     int smaxy = winrec.slidermaxy;
  55.     int wid = winrec.sliderwid;
  56.     int orgx = winrec.orgx;
  57.     int orgy = winrec.orgy;
  58.     int minval = sminx + wid;
  59.     int maxval = smaxx - wid;
  60.     long index;
  61.     short val;
  62.  
  63. #if DBUG
  64.     /* make sure viewport is correct */
  65.     long sizex, sizey;
  66.     getsize(&sizex, &sizey);
  67.     viewport(0,sizex - 1, 0, sizey - 1);
  68.     getorigin(&winrec.orgx, &winrec.orgy);
  69.     ortho2(0.0,(float)(sizex - 1),0.0,(float)(sizey - 1));
  70. #endif
  71.  
  72.     range = maxval - minval;
  73.     oldx = (winrec.slideroldx * (range) + 0.5) + sminx + wid;
  74.  
  75.     do {
  76.     x = getvaluator(MOUSEX) - orgx;
  77.  
  78. #if DBUG
  79.     fprintf(stderr,"org %d %d  pick %d\n",
  80.         winrec.orgx, winrec.orgy, x);
  81. #endif
  82.  
  83.         if (x < minval)
  84.         x = minval;
  85.         if (x > maxval)
  86.         x = maxval;
  87.  
  88.         draw_slider(x - wid, sminy, x + wid, smaxy, 0xcc);
  89.         index = (int)((float)((x-minval)*(MAXDATA-1))/range + 0.5);
  90.         curdata = &curcategory->dataarray[index];
  91.         writesliderdate(curdata->date,(float)(x));
  92.         (*drawmap)(curdata->data);
  93.  
  94.         swapbuffers();
  95.  
  96.         /* keep the back buffer clean */
  97.         setcolor(0xbb, 0xbb, 0xbb);
  98.         sboxfi(oldx - wid, sminy, oldx + wid, smaxy);
  99.         oldx = x;
  100.  
  101.     } while(!(qtest() && qread(&val) == LEFTMOUSE && val == UP));
  102.  
  103.     /* unhighlight the slider */
  104.     frontbuffer(TRUE);
  105.     backbuffer(FALSE);
  106.     draw_slider(oldx - wid, sminy, oldx + wid, smaxy, 0xbb);
  107.     writesliderdate(curdata->date,(float)oldx,(float)(smaxy+sminy) / 2.0);
  108.     frontbuffer(FALSE);
  109.     backbuffer(TRUE);
  110.  
  111.     /* write the data values - (need to unscale them) */
  112. /*
  113.     if (updatetext)
  114.     displaydata(curdata->data);
  115. */
  116.     /* save the x location - save scale for resize */
  117.     winrec.slideroldx = (float)(oldx - sminx - wid) / (range);
  118. }
  119.  
  120.  
  121. draw_slider(minx,miny,maxx,maxy,fillcolor)
  122. int minx, miny, maxx, maxy, fillcolor;
  123. {
  124.     int tmp;
  125.  
  126.     setcolor(0,0,0);
  127.     bgnline();
  128.     v2ixy(maxx,miny);
  129.     v2ixy(maxx,maxy);
  130.     endline();
  131.  
  132.     bgnline();
  133.     v2ixy(minx, miny);
  134.     v2ixy(minx, maxy);
  135.     endline();
  136.  
  137.     minx++;
  138.     maxx--;
  139.  
  140.     setcolor(fillcolor,fillcolor,fillcolor);
  141.     sboxfi(minx,miny,maxx,maxy);
  142.  
  143.     setcolor(0xff,0xff,0xff);
  144.     bgnline();
  145.     v2ixy(minx,maxy);
  146.     v2ixy(maxx,maxy);
  147.     endline();
  148.     maxy--;
  149.  
  150.     tmp = miny + 1;
  151.     setcolor(0xee,0xee,0xee);
  152.     bgnline();
  153.     v2ixy(minx,tmp);
  154.     v2ixy(minx,maxy);
  155.     v2ixy(maxx,maxy);
  156.     v2ixy(maxx,tmp);
  157.     endline();
  158.     minx++;
  159.     maxx--;
  160.     maxy--;
  161.  
  162.     setcolor(0x66,0x66,0x66);
  163.     bgnline();
  164.     v2ixy(minx,miny);
  165.     v2ixy(maxx,miny);
  166.     endline();
  167.     miny++;
  168.  
  169.     tmp = miny + 1;
  170.     setcolor(0xdd,0xdd,0xdd);
  171.     bgnline();
  172.     v2ixy(minx,tmp);
  173.     v2ixy(minx,maxy);
  174.     v2ixy(maxx,maxy);
  175.     v2ixy(maxx,tmp);
  176.     endline();
  177.     minx++;
  178.     maxx--;
  179.  
  180.     setcolor(0x88,0x88,0x88);
  181.     bgnline();
  182.     v2ixy(minx,miny);
  183.     v2ixy(maxx,miny);
  184.     endline();
  185.     miny++;
  186.  
  187.     setcolor(0xaa,0xaa,0xaa);
  188.     bgnline();
  189.     v2ixy(minx,miny);
  190.     v2ixy(maxx,miny);
  191.     endline();
  192. }
  193.  
  194.  
  195.  
  196.